<?php
/**
 *导出
 */
namespace App\Http\Controllers\Excel;



use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Concerns\WithStyles;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use PhpOffice\PhpSpreadsheet\Style\Alignment;


class CheckExcelExport implements FromArray,WithStyles
{
    protected $array;

    /**
     * @param array [
     *                  [1,2,3],
     *                  [4,5,6]
     *              ]
     */
    public function __construct(array $array)
    {
        $this->array = $array;
    }

    public function array(): array
    {
        return $this->array;
    }

    public function styles(Worksheet $sheet)
    {
        for($i=0;$i<=count($this->array[0])-1;$i++){
            $sheet->getColumnDimension(self::getABC($i))->setWidth(14);
        }

        //dd( self::getABC(count($this->array[0])) );
        $sheet->getRowDimension('1')->setRowHeight(28);
        $sheet->getStyle('A1:'.self::getABC(count($this->array[0])-1).'1')->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);  
        $sheet->getStyle('A1:'.self::getABC(count($this->array[0])-1).'1')->getFont()->setBold(true);
    }


    private static function getABC($i)
    {
        $a  = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
        return !empty($a[$i])?$a[$i]:'Z';
    }




    
    
}

?>
